# -*- coding: utf-8 -*-

# Created on 06/08/2010

# Copyright (C) 2010  Sergio Rodrigo

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import cProfile
import pstats

from core.Scene import Scene
from core.ControlManager import ControlManager
from core.Keyboard import *
from core.ActorGraphic import ActorGraphic
from core.Player import Player
from core.Team import Team
from core.Score import Score
from core.Scoreboard import Scoreboard

from PongGame import PongGame
from PongKeyboardControl import *
from PongStick import PongStick
from PongBall import PongBall
from PongBallGraphic import PongBallGraphic
from PongBallStickCollider import PongBallStickCollider
from PongScoreboard import PongScoreboard

import os

def main():
    path_raiz = os.path.join( os.path.dirname( os.path.abspath(__file__) ), '../..' )
    path_stickimage = os.path.join(path_raiz, 'rc/stick.bmp')
    path_ballimage = os.path.join(path_raiz, 'rc/ball.bmp')
    
    sceneWitdh = 800
    sceneHeight = 400
    scene = Scene(sceneWitdh, sceneHeight)
    cManager = ControlManager()
    pong = PongGame(scene, cManager)
    
    stickGraphic1 = ActorGraphic(path_stickimage)
    stick1 = PongStick(100, 200, stickGraphic1)
    stickGraphic1.actor = stick1
    pong.actors.append(stick1)
    
    stickGraphic2 = ActorGraphic(path_stickimage)
    stick2 = PongStick(sceneWitdh - 100, 200, stickGraphic2)
    stickGraphic2.actor = stick2
    pong.actors.append(stick2)
    
    ballGraphic = PongBallGraphic(path_ballimage)
    ball = PongBall(150, 200, 5, 5, 135, ballGraphic)
    ballGraphic.actor = ball
    pong.actors.append(ball)
    
    scene.addElement(stickGraphic1)
    scene.addElement(stickGraphic2)
    scene.addElement(ballGraphic)
    
    keyboard1 = Keyboard()
    #keyboard2 = Keyboard()    ## --> doesn't work
    
    keysActions1 = {KEY_ESCAPE : ACTION_QUIT,
                    KEY_UP : ACTION_MOVE_UP,
                    KEY_DOWN : ACTION_MOVE_DOWN}
    controll = PongKeyboardControl("control 1", keyboard1, stick1, keysActions1)
    cManager.addControl(controll)
    
    keysActions2 = {KEY_ESCAPE : ACTION_QUIT,
                    KEY_Q : ACTION_MOVE_UP,
                    KEY_A : ACTION_MOVE_DOWN}
    control2 = PongKeyboardControl("control 2", keyboard1, stick2, keysActions2)
    cManager.addControl(control2)
    
    ballStickCollider1 = PongBallStickCollider(ball, stick1)
    pong.colliders.append(ballStickCollider1)
    ballStickCollider2 = PongBallStickCollider(ball, stick2)
    pong.colliders.append(ballStickCollider2)
    
    # Scores
    scoreTeam1 = Score("score_team_1", 0)
    scoreTeam2 = Score("score_team_2", 0)
    
    # Players and teams
    team1 = Team("team_1")
    player1 = Player("player_1", team1)
    team1.addActor(player1)
    team1.addScore(scoreTeam1)
    
    team2 = Team("team_2")
    player2 = Player("player_2", team2)
    team2.addActor(player2)
    team2.addScore(scoreTeam2)
    
    pongScoreboard = PongScoreboard()
    pongScoreboard.addScore(scoreTeam1)
    pongScoreboard.addScore(scoreTeam2)
    scene.addElement(pongScoreboard)
    
    pong.player1 = player1
    pong.player2 = player2
    
    pong.initialize()
    pong.main()

# eof
